package com.collections.excercises;

import java.util.Random;

public class SystemArrayCopyVSFor {

	private static Random randomNumber = new Random();
	
	public static void main(String[] args){
		long start,end;
		long resultSystemCopy,resultFor;
		int[] sizes = { 1000, 100_000, 10_000_000};
		
		
		for (int i = 0;i<sizes.length;i++){
			int[] srcArray = new int[sizes[i]];
			int[] destArray = new int[sizes[i]];
			fillArray(srcArray,sizes[i]);
		
			start = System.nanoTime();
			System.arraycopy(srcArray, 0, destArray, 0, sizes[i]);
			end = System.nanoTime();
			resultSystemCopy = end-start;
			
			fillArray(srcArray,sizes[i]);
			destArray = new int[sizes[i]];
			start = System.nanoTime();
			for (int j = 0; j < destArray.length; j++) {
				destArray[j] = srcArray[j];
			}
			end = System.nanoTime();
			resultFor = end-start;
			System.out.println(resultSystemCopy+" / "+resultFor+" = "+(double)resultSystemCopy/resultFor);
		}
	}
	
	private static void fillArray(int[] array, final int SIZE) {
	
		for (int i = 0; i < SIZE; i++) {
			array[i] = randomNumber.nextInt();
		}
	}
	
}